
import 'dart:io';

import 'package:flutter/services.dart';
///信息流广告（单个）、Draw广告、Banner广告、开屏广告
class FCsjGroMoreAds {
  static final FCsjGroMoreAds _singleton = FCsjGroMoreAds._internal();
  static FCsjGroMoreAds get instance => FCsjGroMoreAds();
  factory FCsjGroMoreAds() {
    return _singleton;
  }
  FCsjGroMoreAds._internal(){
    //做一些操作
  }
  ///根据单一原则，方法通道只负责方法传参到原生层
  static const MethodChannel _methodChannel =  MethodChannel('com.xt.fcsj.gromore.ads');
  ///根据单一原则，事件通道只接收原生发过来的消息
  static const EventChannel _eventChannel =  EventChannel('com.xt.fcsj.gromore.ads.event');

  //消息回调、最好全局设置
  Future<void> onEventMsgCallBack(Function(dynamic eventData) eventMsgCallBack)async{
    _eventChannel.receiveBroadcastStream().listen((eventMsg) {
      if(eventMsgCallBack!=null)eventMsgCallBack(eventMsg);
    });
  }

  ///iOS端请求跟踪透明度授权
  Future<bool> requestIosIDFA() async {
    if (!Platform.isIOS)return true;
    bool result = await _methodChannel.invokeMethod('requestIosIDFA');
    return result;
  }
  ///Android端动态请求相关权限
  Future<bool> requestAndroidPermissionIfNecessary() async {
    if (!Platform.isAndroid)return true;
    bool result = await _methodChannel.invokeMethod('requestAndroidPermissionIfNecessary');
    return result;
  }
  /// 广告SDK初始化
  /// appId 穿山甲平台注册的应用id
  /// allowShowNotify 是否允许通知栏提示
  /// directDownloadNetworkType 哪些网络方式下载网络方式：MOBILE：1、2G：2、3G：3、WIFI：4、4G：5、5G：6
  Future<bool> initCsjAd(
      {
        required String appId,
        bool? allowShowNotify,
        List<int>? directDownloadNetworkType,
      }) async {
    final bool result = await _methodChannel.invokeMethod(
      'initCsjAd',
      {
        'appId': appId,
        'allowShowNotify': allowShowNotify??true,
        'directDownloadNetworkType': directDownloadNetworkType??[],
      },
    );
    return result;
  }

  /// 信息流广告列表
  /// mMediaId：广告位id
  /// width：宽度
  /// height：高度
  /// count：广告数量，默认3个
  Future<List<int>> showFeedListAd({required String mMediaId,int? width, int? height, int? count}) async {
    final List<int> result = await _methodChannel.invokeMethod(
      'showFeedListAd',
      {
        'mMediaId': mMediaId,
        'width': width,
        'height': height,
        'count': count??3,
      },
    );
    return result;
  }
  /// 激励视频广告
  /// mMediaId：广告位id
  Future<bool> showRewardAd({required String mMediaId}) async {
    final bool result = await _methodChannel.invokeMethod(
      'showRewardAd',
      {
        'mMediaId': mMediaId,
      },
    );
    return result;
  }
  /// 插全屏广告
  /// mMediaId：广告位id
  Future<bool> showFullInteractionAd({required String mMediaId}) async {
    final bool result = await _methodChannel.invokeMethod(
      'showFullInteractionAd',
      {
        'mMediaId': mMediaId,
      },
    );
    return result;
  }


}
